﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace FOBTV.Web.FOBTV2012.en
{
    public partial class participation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

		protected void lbtMou_Click(object sender, EventArgs e)
		{
			string path;
			try
			{
				path = Request.PhysicalApplicationPath + "PDF/MOU.pdf";// "/" + Session["pdfpath"].ToString() + "/PDF/" + Session["mlmc"].ToString() + ".pdf";
			}
			catch (Exception)
			{
				return;
			}
			System.IO.Stream iStream = null;
			byte[] buffer = new Byte[10000];
			int length;
			long dataToRead;
			string filename = "MOU.pdf";

			try
			{
				iStream = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
				dataToRead = iStream.Length;
				Response.Clear();
				Response.ClearHeaders();
				Response.ClearContent();
				Response.ContentType = "application/pdf"; //文件类型  
				Response.AddHeader("Content-Length", dataToRead.ToString());//添加文件长度，进而显示进度  
				Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
				while (dataToRead > 0)
				{
					if (Response.IsClientConnected)
					{
						length = iStream.Read(buffer, 0, 10000);
						Response.OutputStream.Write(buffer, 0, length);
						Response.Flush();

						buffer = new Byte[10000];
						dataToRead = dataToRead - length;
					}
					else
					{
						dataToRead = -1;
					}
				}

			}
			catch (Exception ex)
			{
				Response.Write("error!");
			}
			finally
			{
				if (iStream != null)
				{
					iStream.Close();
				}
				//结束响应，否则将导致网页内容被输出到文件，进而文件无法打开  
				Response.End();
			}   
		}

		protected void lbtApplication_Click(object sender, EventArgs e)
		{
			string path;
			try
			{
				path = Request.PhysicalApplicationPath + "PDF/ApplicationForm.pdf";// "/" + Session["pdfpath"].ToString() + "/PDF/" + Session["mlmc"].ToString() + ".pdf";
			}
			catch (Exception)
			{
				return;
			}
			System.IO.Stream iStream = null;
			byte[] buffer = new Byte[10000];
			int length;
			long dataToRead;
			string filename = "ApplicationForm.pdf";

			try
			{
				iStream = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
				dataToRead = iStream.Length;
				Response.Clear();
				Response.ClearHeaders();
				Response.ClearContent();
				Response.ContentType = "application/pdf"; //文件类型  
				Response.AddHeader("Content-Length", dataToRead.ToString());//添加文件长度，进而显示进度  
				Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
				while (dataToRead > 0)
				{
					if (Response.IsClientConnected)
					{
						length = iStream.Read(buffer, 0, 10000);
						Response.OutputStream.Write(buffer, 0, length);
						Response.Flush();

						buffer = new Byte[10000];
						dataToRead = dataToRead - length;
					}
					else
					{
						dataToRead = -1;
					}
				}

			}
			catch (Exception ex)
			{
				Response.Write("error!");
			}
			finally
			{
				if (iStream != null)
				{
					iStream.Close();
				}
				//结束响应，否则将导致网页内容被输出到文件，进而文件无法打开  
				Response.End();
			}
		}
    }
}